package com.shushan.manager;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;

import com.shushan.base.NavigationLoseActivity;
import com.shushan.manager.adapter.SoftMgPagerAdapter;
import com.shushan.shushanbao.BabyApplication;
import com.shushan.shushanbao.R;
import com.shushan.util.UmengEventUtil;

/**
 * @ClassName: SoftWareMgActivity
 * @Desciption: 软件管理界面
 * @author: yichaohua
 * @date: 2018-07-17
 */
public class SoftWareMgActivity extends NavigationLoseActivity implements ViewPager.OnPageChangeListener {

    private static final String TAG = "SoftWareMgActivity";

    private TabLayout tabLayout;
    private ViewPager viewPager;
    private SoftMgPagerAdapter softMgPagerAdapter;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setTitle("软件管控");

        setContentView(R.layout.soft_mg_activity);

        initView();

        initTabLayout();

        UmengEventUtil.onEvent(BabyApplication.getInstance(),"soft_manager_page_id");
    }

    private void initView() {
        tabLayout = findViewById(R.id.soft_mg_tl);
        viewPager = findViewById(R.id.soft_mg_vp);
    }

    private void initTabLayout() {
        softMgPagerAdapter = new SoftMgPagerAdapter(getSupportFragmentManager(), this);
        viewPager.setAdapter(softMgPagerAdapter);
        viewPager.addOnPageChangeListener(this);

        tabLayout.setupWithViewPager(viewPager);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        //滑动监听加载数据，一次只加载一个标签页
        ((SoftWareMgFragment)softMgPagerAdapter.getItem(position)).sendMessage();

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
